package org.rcy.framework.data.datasource;

/**
 * 支持的数据库版本
 */
public enum DatabaseVersion {
	MYSQL_5_6("5.6"), MYSQL_5_7("5.7"), MYSQL_8_0("8.0"),
	ORACLE_11G("11g"), ORACLE_12C("12c"), ORACLE_19C("19c"),
	SQLSERVER_2012("11"), SQLSERVER_2014("12"), SQLSERVER_2016("13"), SQLSERVER_2017("14"), SQLSERVER_2019("15")
	,DM_7("7"),DM_8("8"), OSCAR_7("7"), KINGBASE_8("8"), OPENGAUSS("2.0.0");

	DatabaseVersion(String name) {
	}

	public static boolean isSupportVesion(Database db, String databaseVesion) {
		boolean support = false;
		if (db == Database.MYSQL) {
			for (String version : getMySQLVersion()) {
				if (databaseVesion.contains(version)) {
					support = true;
					break;
				}
			}
			return support;
		}
		if (db == Database.ORACLE) {
			for (String version : getOracleVersion()) {
				if (databaseVesion.contains(version)) {
					support = true;
					break;
				}
			}
			return support;
		}
		if (db == Database.SQLSERVER) {
			for (String version : getSqlServerVersion()) {
				if (databaseVesion.startsWith(version)) {
					support = true;
					break;
				}
			}
			return support;
		}
		if (db == Database.DM) {
			for (String version : getDmVersion()) {
				if (databaseVesion.startsWith(version)) {
					support = true;
					break;
				}
			}
			return support;
		}
		if (db == Database.OSCAR) {
			for (String version : getOscarVersion()) {
				if (databaseVesion.contains(version)) {
					support = true;
					break;
				}
			}
			return support;
		}
		if (db == Database.KINGBASEES) {
			for (String version : getKingBaseVersion()) {
				if (databaseVesion.contains(version)) {
					support = true;
					break;
				}
			}
			return support;
		}
		if (db == Database.POSTGRESQL) {
			for (String version : getOpenGaussVersion()) {
				if (databaseVesion.contains(version)) {
					support = true;
					break;
				}
			}
			return support;
		}
		return false;
	}

	public static String[] getMySQLVersion() {
		return new String[]{"5.6", "5.7", "8.0"};
	}

	public static String[] getOracleVersion() {
		return new String[]{"11g", "12c", "19c"};
	}

	public static String[] getSqlServerVersion() {
		return new String[]{"11", "12", "13", "14", "15"};
	}
	
	public static String[] getDmVersion() {
		return new String[] { "7", "8" };
	}
	
	public static String[] getOscarVersion() {
		return new String[] { "7.0" };
	}

	public static String[] getKingBaseVersion() {
		return new String[] { "8" };
	}

	private static String[] getOpenGaussVersion() {
		return new String[] { "2.0.0" };
	}
}
